<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-row>
        <el-form-item label="关联数据集" prop="dataset">
          <el-select
            v-model="queryParams.dataset"
            placeholder="请关联数据集"
            clearable
            style="width: 300px"
          >
            <el-option
              v-for="dict in this.datasetList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="IEC104报文" prop="message">
          <el-input
            v-model="queryParams.message"
            placeholder="IEC104上传的总召(或变化上送)报文 多行用换行符分割"
            clearable
            type="textarea" rows="10"
            style="width: 800px;"
          />
        </el-form-item>
      </el-row>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">解析</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <hr>
    <el-table v-if="this.iShow" v-loading="loading" :data="infoObjComputeList">
      <el-table-column label="信息对象地址" prop="infoObjAddr" align="center" width="400"/>
      <el-table-column label="最大值" prop="maxValue" align="center" width="200"/>
      <el-table-column label="最小值" prop="minValue" align="center" width="200"/>
      <el-table-column label="平均值" prop="avgValue" align="center" width="200"/>
      <el-table-column label="总数" prop="count" align="center" width="200"/>
    </el-table>

    <el-table v-if="this.iShow" v-loading="loading" :data="infoObjGroupList">
      <el-table-column label="开始值" prop="startValue" align="center" width="200"/>
      <el-table-column label="结束值" prop="endValue" align="center" width="200"/>
      <el-table-column label="总数" prop="totalCount" align="center" width="200"/>
    </el-table>

    <el-table v-if="this.iShow" v-loading="loading" :data="infoObjMatchList">
      <el-table-column label="信息对象地址" prop="startValue" align="center" width="200"/>
      <el-table-column label="状态" prop="endValue" align="center" width="200"/>
    </el-table>

  </div>
</template>

<script>
import {getProtocoliIec104v2} from "@/api/system/point_parser";

export default {
  name: "IEC104",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      frameType: undefined,
      // U帧 S帧 I帧
      uFrame: {},
      sFrame: {},
      iFrame: {},
      uShow: false,
      iShow: false,
      sShow: false,
      infoObjList: [],
      infoObjGroupList:[],
      infoObjComputeList:[],
      infoObjMatchList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 菜单列表
      datasetList:[],
      // 查询参数
      queryParams: {
        dataset: '',
        message: ''
      },
      defaultProps: {
        children: "children",
        label: "label"
      }

    };
  },
  created() {
   this.loading = false;
    //this.queryData();
    this.queryDatasetList();
  },
  methods: {
    queryDatasetList(){

    },
    /** 查询iec104报文 */
    queryData() {
      this.loading = true;
      // 判断条件是否为空
      if (this.queryParams.message === '' || this.queryParams.message === undefined) {
        this.$alert("请输入IEC104上传的总召(或变化上送)报文", '系统提示', {
          dangerouslyUseHTMLString: true,
          type: 'success'
        });
        return;
      }
      getProtocoliIec104v2(this.queryParams.dataset,this.queryParams.message).then(response => {
          this.infoObjComputeList = response.data.infoObjComputeList;
          this.infoObjGroupList = response.data.infoObjGroupList;
          this.infoObjMatchList = response.data.infoObjMatchList;
          this.loading = false;
          this.iShow = true;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryData();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      //this.handleQuery();
      this.iShow = false;
      this.uShow = false;
      this.sShow = false;
    }
  }
};
</script>
